package org.game.msgBuilder;

import java.util.List;

import org.cfg.EndlessCloisterLevelCfg;
import org.cfg.cache.EndlessCloisterLevelCfgCache;
import org.game.db.bean.Player;
import org.game.db.bean.PlayerData;
import org.game.db.proxy.bean.PlayerDataProxy;
import org.game.db.vo.PlayerDataVO.EndlessVO;
import org.game.manager.EndlessCloisterManager;
import org.game.protobuf.s2c.S2CEndlessCloisterMsg.EndlessCloisterInfo;
import org.game.protobuf.s2c.S2CEndlessCloisterMsg.RspEndlessCloisterInfo;
import org.game.protobuf.s2c.S2CEndlessCloisterMsg.RspPassStageEndless;
import org.game.protobuf.s2c.S2CEndlessCloisterMsg.RspStartFightEndless;
import org.game.protobuf.s2c.S2CShareMsg.RewardsMsg;

/**
 * 无尽回廊消息构建器
 * 
 * @author liu.jiang
 * @date 2018年3月14日
 */
public class EndlessCloisterMsgBuilder {

    /** 创建无尽回廊信息 */
    public static RspEndlessCloisterInfo createEndlessCloisterInfo(Player player) {
        PlayerData playerData = player.getPlayerDatasFkPlayerId();
        PlayerDataProxy pdProxy = playerData.getPlayerDataProxy();
        EndlessVO endlessVO = pdProxy.getEndlessVO();
        RspEndlessCloisterInfo.Builder builder = RspEndlessCloisterInfo.newBuilder();
        builder.setInfo(createBaseInfo(endlessVO));
        return builder.build();
    }

    /** 创建无尽回廊开始战斗响应信息 */
    public static RspStartFightEndless createRspStartFightEndless(EndlessVO endlessVO,int startLevelCid) {
        RspStartFightEndless.Builder builder = RspStartFightEndless.newBuilder();
        builder.setLevelCid(startLevelCid);
        return builder.build();
    }

    /** 创建无尽回廊通关响应信息 */
    public static RspPassStageEndless createRspPassStageEndless(EndlessVO endlessVO,List<RewardsMsg> rewards,int nextLevelCid) {
        RspPassStageEndless.Builder builder = RspPassStageEndless.newBuilder();
        builder.setNextLevelCid(nextLevelCid);
        builder.addAllRewards(rewards);
        return builder.build();
    }
    
    /** 创建无尽回廊基础信息 */
    public static EndlessCloisterInfo.Builder createBaseInfo(EndlessVO endlessVO) {
        EndlessCloisterInfo.Builder info = EndlessCloisterInfo.newBuilder();
        info.setHistoryBest(endlessVO.getHistoryBest());
        EndlessCloisterLevelCfg cfg =
                EndlessCloisterLevelCfgCache.me().getById(endlessVO.getTodayBest());
        int todayBest = cfg == null ? 0 : cfg.getOrder();
        info.setTodayBest(todayBest);
        info.setTodayCostTime(endlessVO.getTodayCostTime());
        info.setStep(EndlessCloisterManager.me().getClientStep());
        info.setNextStepTime(EndlessCloisterManager.me().getNextStepTime());
        return info;
    }

}
